//
//  UIStackView+ZKChain.m
//  ChainFun
//
//  Created by 洪绵卫 on 2022/1/11.
//

#import "UIStackView+ZKChain.h"

@implementation UIStackView (ZKChain)

+ (UIStackView * _Nonnull (^)(void))zk_allocInit{
    return ^{
         UIStackView *v = [[UIStackView alloc]init];
        return v;
    };
}

+ (UIStackView * _Nonnull (^)(CGRect))zk_allocInitWithFrame{
    return ^(CGRect rect){
        UIStackView * v = [[UIStackView alloc]initWithFrame:rect];
        return v;
    };
}

- (UIStackView * _Nonnull (^)(CGRect))zk_frame{
    return ^(CGRect rect){
        self.frame = rect;
        return self;
    };
}

- (UIStackView * _Nonnull (^)(UIColor * _Nonnull))zk_backgroundColor{
    return ^(UIColor *color){
        self.backgroundColor = color;
        return self;
    };
}

- (UIStackView * _Nonnull (^)(UIView * _Nonnull))zk_addToSuperView{
    return ^(UIView *view){
        [view addSubview:self];
        return self;
    };
}

- (UIStackView * _Nonnull (^)(BOOL))zk_userInteractionEnabled{
    return ^(BOOL isUserInteractionEnabled){
        self.userInteractionEnabled = isUserInteractionEnabled;
        return self;
    };
}

- (UIStackView * _Nonnull (^)(NSInteger))zk_tag{
    return ^(NSInteger tag){
        self.tag = tag;
        return self;
    };
}

- (UIStackView * _Nonnull (^)(CGRect))zk_bounds;{
    return ^(CGRect rect){
        self.bounds = rect;
        return self;
    };
}

- (UIStackView * _Nonnull (^)(CGPoint))zk_center{
    return ^(CGPoint point){
        self.center = point;
        return self;
    };
}

- (UIStackView * _Nonnull (^)(CGFloat))zk_alpha{
    return ^(CGFloat value){
        self.alpha = value;
        return self;
    };
}

- (UIStackView * _Nonnull (^)(BOOL))zk_hidden{
    return ^(BOOL isHidden){
        self.hidden = isHidden;
        return self;
    };
}

- (UIStackView * _Nonnull (^)(UIColor * _Nonnull))zk_tintColor{
    return ^(UIColor *col){
        self.tintColor = col;
        return self;
    };
}

#pragma mark 对应UIStackView 的一些属性
- (UIStackView * _Nonnull (^)(UILayoutConstraintAxis))zk_axis{
    return ^(UILayoutConstraintAxis axis){
        self.axis = axis;
        return self;
    };
}

- (UIStackView * _Nonnull (^)(UIStackViewDistribution))zk_distribution{
    return ^(UIStackViewDistribution distribution){
        self.distribution = distribution;
        return self;
    };
}

- (UIStackView * _Nonnull (^)(UIStackViewAlignment))zk_alignment{
    return ^(UIStackViewAlignment alignment){
        self.alignment = alignment;
        return self;
    };
}

- (UIStackView * _Nonnull (^)(CGFloat))zk_spacing{
    return ^(CGFloat value){
        self.spacing = value;
        return self;
    };
}

- (UIStackView * _Nonnull (^)(BOOL))zk_baselineRelativeArrangement{
    return ^(BOOL value){
        self.baselineRelativeArrangement = value;
        return self;
    };
}

- (UIStackView * _Nonnull (^)(BOOL))zk_layoutMarginsRelativeArrangement{
    return ^(BOOL value){
        self.layoutMarginsRelativeArrangement = value;
        return self;
    };
}

#pragma mark 对应UIStackView 的一些方法

- (UIStackView * _Nonnull (^)(NSArray<__kindof UIView *> *))zk_initWithArrangedSubviews{
    return ^(NSArray<__kindof UIView *> * array){
        UIStackView * stackView = [[UIStackView alloc]initWithArrangedSubviews:array];
        return stackView;
    };
}

/// 添加一个子视图至Arranged中
- (UIStackView * _Nonnull (^)(UIView * _Nonnull))zk_addArrangedSubview{
    return ^(UIView *view){
        [self addArrangedSubview:view];
        return self;
    };
}

/// 从一个Arranged中移除一个子视图
- (UIStackView * _Nonnull (^)(UIView * _Nonnull))zk_removeArrangedSubview{
    return ^(UIView * view){
        [self removeArrangedSubview:view];
        return self;
    };
}

/// 插入一个子视图至Arranged中指定的位置
- (UIStackView * _Nonnull (^)(UIView * _Nonnull,NSUInteger))zk_insertArrangedSubviewToIndex{
    return ^(UIView * view,NSUInteger index){
        [self insertArrangedSubview:view atIndex:index];
        return self;
    };
}

@end
